package view;

import java.text.ParseException;
import java.util.Scanner;

import controller.ControllerForDB;

import checking.InputValidation;

import model.Activity;

public class MenuHelperForActivity {
	
	static InputValidation oValidation = new InputValidation();
	static ControllerForDB controller = new ControllerForDB();
	static MenuHelperForTask oTaskMenuHelper = new MenuHelperForTask();
	
	
	public  void removeActivityFromProject(int proId) {
		
		System.out.println("Your activities are:\n");
		controller.getAllActivites(proId);
		
		System.out
				.println("Please enter Project id that you want to remove;\n");
		Scanner actNumber = new Scanner(System.in);
		String aNumber = actNumber.next();
		int actNumb = oValidation.checkInteger(aNumber);
		
		controller.removeActivityFromDB(actNumb);

		
	}

	public void addActivityToProject(int proId) throws ParseException {

		Activity addedActivity = null;

		System.out.println("Please enter activity description;\n");
		Scanner actDesc = new Scanner(System.in);
		String activityDesc = actDesc.next();
		System.out.println("\n");

		try {

			oValidation.validateString(activityDesc);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Please enter valid entries!");
		}

		System.out.println("Please enter activity deliverable;\n");
		Scanner actDeliverable = new Scanner(System.in);
		String activityDel = actDeliverable.next();
		System.out.println("\n");

		try {

			oValidation.validateString(activityDel);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Please enter valid entries!");

		}

		System.out
				.println("Please enter the start date of the activity as format 'dd-MM-yyyy';\n");
		Scanner actStartDate = new Scanner(System.in);
		String actDate = actStartDate.next();
		System.out.println("\n");
		if (!(oValidation.date_control(actDate))) {
			System.out.println("Invalid date entry!!!");

		}

		addedActivity = controller.addActivityToDB(activityDesc, actDate,
				activityDel, proId);

		System.out
				.println(addedActivity.toString()
						+ " activity is added to your project. If you want to continue there are your options;\n");
		System.out.println("1- Add Task\n");
		System.out.println("2- Exit");

		Scanner response3 = new Scanner(System.in);
		String thirdResp = response3.next();
		int tResp = oValidation.checkInteger(thirdResp);
		oValidation.validateResponse(tResp, 2);

		if (tResp == 1) {
			oTaskMenuHelper.addTaskToActivity(addedActivity.getNumber());
		}
	}

	public  void updateActivityFromProject(int proId) {

		System.out.println("Your activities are;\n");
		controller.getAllActivites(proId);

		System.out
				.println("Please enter the id of the activity you want to update;\n");
		Scanner actId = new Scanner(System.in);
		int activityId = actId.nextInt();
		System.out.println("\n");

		System.out.println("Please enter activity description;\n");
		Scanner actDesc = new Scanner(System.in);
		String activityDesc = actDesc.next();
		System.out.println("\n");

		try {

			oValidation.validateString(activityDesc);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Please enter valid entries!");
		}

		System.out.println("Please enter activity deliverable;\n");
		Scanner actDeliverable = new Scanner(System.in);
		String activityDel = actDeliverable.next();
		System.out.println("\n");

		try {

			oValidation.validateString(activityDel);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("Please enter valid entries!");

		}

		System.out
				.println("Please enter the start date of the activity as format 'dd-MM-yyyy';\n");
		Scanner actStartDate = new Scanner(System.in);
		String actDate = actStartDate.next();
		System.out.println("\n");
		if (!(oValidation.date_control(actDate))) {
			System.out.println("Invalid date entry!!!");

		}

		controller.updateActivityFromDB(activityId, activityDesc, actDate,
				activityDel);
	}

}
